<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 编写函数 URL处理 "http://www.xxx.com/?name=bf&age=23&from=baidu" ,
        // 想办法获取url的参数信息(?后边) 包装成对象{name:'bf',age:23,form:'baidu'}

        var url = 'http://www.xxx.com/?name=bf&age=23&from=baidu';

        function getInfo(url) {
            // 获取？索引
            getIdx = url.indexOf('?');
            url = url.substr(getIdx + 1);
            // 以&切片，得到arr
            var arr = url.split('&');
            var obj = {};
            for (var i = 0; i < arr.length; i++) {
                // 对arr中每一项以=切片
                var arr2 = arr[i].split('=');
                // 拼装
                obj[arr2[0]] = arr2[1];
            }
            return obj;
        }
        console.log(getInfo(url));
    </script>
</body>
</html>